package test0ne.多线程;

import java.util.concurrent.ConcurrentLinkedQueue;

public class ConcurrentLinkedQueueTest {

    private static volatile int data = 1;

    private static ConcurrentLinkedQueue queue = new ConcurrentLinkedQueue();

    public static void main(String[] args) {
        new Thread(new Adder(), "-----添加队列------").start();

        new Thread(new Worker(), "----线程----").start();

    }




    static class Worker implements Runnable{

        @Override
        public void run() {
            while (true) {
                if(!queue.isEmpty()) {
                    System.out.println("=======开始炒菜=======");
                    System.out.println(queue.poll());
                }else {
                    System.out.println("队列是空");
                    SleepUtils.second(2);
                }
            }
        }
    }

    static class Adder implements Runnable{

        @Override
        public void run() {
            while (true) {
                if(queue.isEmpty()) {
                    System.out.println("=======开始加菜=======");
                    queue.offer(data++);
                }else {
                    SleepUtils.second(1);
                }
            }
        }
    }
}
